package com.example.socketdemo.nio.one;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.nio.channels.SocketChannel;
import java.util.Scanner;

public class Client {

    public static void main(String[] args) {
        try {
            SocketChannel schannel = SocketChannel.open(
                    new InetSocketAddress("127.0.0.1", 9999));
            schannel.configureBlocking(false);
            ByteBuffer buf = ByteBuffer.allocate(1024);
            Scanner sc = new Scanner(System.in);
            while(true){
                System.out.println("情说：");
                String s = sc.nextLine();
                buf.put(("涂山红红: " + s).getBytes());
                buf.flip();
                schannel.write(buf);
                buf.clear();
            }

        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}
